import 'package:flutter/material.dart';

class TableRoute extends StatefulWidget {
  const TableRoute({Key? key}) : super(key: key);

  @override
  _TableRouteState createState() => _TableRouteState();
}

class _TableRouteState extends State<TableRoute> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('table表格'),
      ),
      body: Column(
        children: [
          Table(
            border: TableBorder.all(color: Colors.grey[400]!),
            defaultVerticalAlignment: TableCellVerticalAlignment.middle,
            children: [
              TableRow(
                  decoration: BoxDecoration(color: Colors.grey[200]),
                  children: _addPadding([
                    const Text("姓名"),
                    const Text("性别"),
                    const Text("备注"),
                  ])),
              TableRow(
                  decoration: BoxDecoration(color: Colors.grey[200]),
                  children: _addPadding([
                    const Text("张三"),
                    const Text("男"),
                    const Text("不予置评"),
                  ]))
            ],
            
          ),
          DataTable(
            sortColumnIndex: 0,
            sortAscending: true,
            rows:const <DataRow>[
              DataRow(cells: [
                DataCell(Text('1')),
                DataCell(Text('28.5')),
              ]),
               DataRow(cells: [
                DataCell(Text('2')),
                DataCell(Text('30.5')),
              ])
            ],
            columns: <DataColumn>[
              DataColumn(label: Text('id'),numeric: true,onSort: (a,b){
                print("$a $b");

              }),
               DataColumn(label: Text('价格￥'),numeric: true),
            ],
            )
        ],
      ),
    );
  }
}


_addPadding(List<Widget> children){
  return children.map((e)=>Padding(padding: EdgeInsets.all(6),child: e,)).toList();
}

